function Adaptive(){
	$('.print-tbody').width( $(".admin").width()+'px');
	$('.print-tbody').height( $(".admin").height()-110+'px');
//  判断是否出现滚动条
	var obj=$(".print-tbody"); 
	if(obj.prop('scrollHeight')>obj.prop('clientHeight')||obj.prop('offsetHeight')>obj.prop('clientHeight')){
		$('.print-tbody').width( $(".admin").width()+1+'px');
	}
}
$(function(){
	Adaptive();
	$(".coll_body").eq(0).show();
	$(".coll_body").eq(0).children('a').eq(0).addClass("active");
	$(".Collapsing").eq(0).children('a').children('span').addClass("rotate");
	$(".Collapsing").eq(0).click(function(){
		$(".Collapsing").eq(0).toggleClass("active");
		$(this).children('.coll_body').children('a').eq(0).toggleClass("active");
	})
})
//  打印机手风琴折叠效果
	$("body").on("click",".coll-td",function(){
    	var cid=$(this).attr("value");
    	var that=this;
    	k=false;
    	k=!k;
    	if(k){
	    	$.ajax({  
		        type : "GET",  
		        url : serverIP+'/user/printInfo/listByCustom',  
		        data: {
		        	cId:cid 
		        },
		        xhrFields:{
		            withCredentials: true    // 设置sessionId相同
		        },
		        success:function(data){
					var strVar = "";
					data.data.map(function(u){
						var nowStatus=u.nowStatus;
						if(nowStatus=="01"){
							nowStatus="<font color=green>正常</font>";
						}else if(nowStatus=="02"){
							nowStatus="<font color=red>报错</font>";
						}else if(nowStatus=="03"){
							nowStatus="<font color=orange>报废</font>";
						}
						strVar += "              <li>";
						strVar += "              	<p>";
					    strVar += "                		<span class=\"printId\">"+u.printId+"<\/span>\n";
					    strVar += "                		<span>"+u.brandName+"<\/span>\n";
					    strVar += "                		<span>"+u.model+"<\/span>\n";
					    strVar += "                		<span>"+u.printName+"<\/span>\n";
					    strVar += "                		<span>"+nowStatus+"<\/span>\n";
					    strVar += "              	<\/p>";
					    strVar += "              <\/li>";
					})
					$(that).find('.print-list').html(strVar);
		        }  
		    });
		}
        $(this).find('.print-list').slideToggle(0);
        $(this).find('.print-num').toggle();
    });
//  折叠全部打开
	$(".table-open").click(function(){
        $(".print-num").each(function(){
        	$(this).parent(".coll-td").click();
        });
        $(".table-open").children('span').toggleClass("current");
//      判断是否出现滚动条
        var obj=$(".print-tbody"); 
		if(obj.prop('scrollHeight')>obj.prop('clientHeight')||obj.prop('offsetHeight')>obj.prop('clientHeight')){
			$('.print-tbody').width( $(".admin").width()+'px');
		}else{
			$('.print-tbody').width( $(".admin").width()+'px');
		}
    });
//	获取打印机列表
	var pageSize = 15;
	var currentPage = 1; 
	ajaxTest(currentPage);
	
	function ajaxTest(currentPage) {
		$.ajax({
				type:"post",
				url:serverIP+"/user/printInfo/GetNumByCustom",
				dataType:"json",
				xhrFields: {
	                withCredentials: true    // 设置sessionId相同
	            },
	            data: {page:currentPage,pageSize:pageSize},
				success:function (data) {
					let result=data.data.list.result;
					clength=result.length;
					var strVar = "";
					result.map(function(u){
						if(u.cName==undefined){
							cName="";
						}else{
							cName=u.cName;
						}
						strVar += "              <tr>";
					    strVar += "                <td>"+u.cId+"<\/td>\n";
					    strVar += "                <td>"+cName+"<\/td>\n";
					    strVar += "                <td>"+u.remark+"<\/td>\n";
					    strVar += "                <td class=\"coll-td\" value="+u.cId+">\n";
					    strVar += "                		<span class=\"print-num\">"+u.printSum+" <i class=\"icon-caret-down\"></i></span>\n";
					    strVar += "                		<div class=\"print-list\">\n";
					    strVar += "                			<ul>\n";
					    strVar += "                			</ul>\n";
					    strVar += "                		<\/div>\n";
					    strVar += "                <\/td>\n"; 
					    strVar += "             <\/tr>";
					})
					$('.print-tbody').html(strVar);
					if(clength<5){
						$(".table-open").click();
					}
				//分页
					/*$("#page").paging({
						pageNo: data.data.list.curPage,
						totalPage: data.data.list.totalPage,
						totalSize: data.data.list.totalRow,
						callback: function(currentPage) {
							ajaxTest(currentPage); 
						}
					});*/
				}
		})
	}
	
//监听浏览器窗口变化
window.onresize = function(){
	var bodyH=$("body").height();
	$(".leftbar").height(bodyH-45+"px");
	$(".content").height(bodyH-45+"px");
	$(".admin").height($(".content").height()-45+"px");
	Adaptive();
}
//跳转打印机详情
$("body").on("click",".print-list p",function(event){
	event.stopPropagation();
	var pid=$(this).find('.printId').text();
	window.location.href="printdetail.html?pid="+pid;
})
